package com.xbongbong.paas.service.stage;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.CustomerStageErrorCodeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * 阶段设置策略工厂
 * @author 李少杰
 * @version v1.0.0
 * @date 2021/11/26 13:56
 */
@Component
public class StageSettingsFactory {

    @Resource
    private Map<Integer, StageSettingsStrategy> stageSettingsMap;

    /**
     * 获取阶段设置策略
     * @param type
     * @return
     * @throws XbbException
     */
    public StageSettingsStrategy getStageSettingsStrategy(Integer type) throws XbbException {
        StageSettingsStrategy stageSettingsStrategy = stageSettingsMap.get(type);
        if (Objects.isNull(stageSettingsStrategy)) {
            throw new XbbException(CustomerStageErrorCodeEnum.API_ERROR_238023);
        }
        return stageSettingsStrategy;
    }
}
